package com.neuedu.web.dao;

import com.neuedu.web.common.BaseDao;
import com.neuedu.web.po.RegisterPO;
import com.neuedu.web.po.RegisterPO;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

/**
 * @author 金山
 * 项目：jdbc-dao
 * site: https://blog.fulfill.com.cn
 * 描述  register 表的数据访问对象
 * @data  2024年11月21日13:38:03
 */
public class RegisterDao extends BaseDao<RegisterPO> {



    public List<RegisterPO> selectAll(  String sql, Object... params) throws NoSuchFieldException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
        return super.selectAll(RegisterPO.class , sql,params);
    }
    public List<RegisterPO> selectPage( int current, int size, String sql, Object... params) throws NoSuchFieldException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
        return super.selectPage(RegisterPO.class , current ,size,sql,params);
    }



    public RegisterPO selectById(long id) throws NoSuchFieldException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {


        String sql = "select * from register where regist_id= ?";
        return super.selectOne(RegisterPO.class,sql,id);

    }



    public int insert(RegisterPO register) {
        String sql = "INSERT INTO `register` (     name,gender,age,birthday,visit_time,dept_id,regist_level,readme,present,present_treat,history,allergy,disease,suit,drug,userid,book,fee,status) VALUES(  ?,?,?, ?,?,? , ?,?,?, ?,?,? ,  ?,?,?, ?,?,?,  ?)  ";
        int count = super.update(sql,
                register.getName(),
                register.getGender(),
                register.getAge(),
                register.getBirthday(),
                register.getVisitTime(),
                register.getDeptId(),
                register.getRegistLevel(),
                register.getReadme(),
                register.getPresent(),
                register.getPresentTreat(),
                register.getHistory(),
                register.getAllergy(),
                register.getDisease(),
                register.getSuit(),
                register.getDrug(),
                register.getUserid(),
                register.getBook(),
                register.getFee(),
                register.getStatus()
        );

        return count;

    }


    public int update(RegisterPO register) {
        StringBuffer sql = new StringBuffer();

        sql.append("  update              ");
        sql.append("    `register`  ");
        sql.append("  set ");
        sql.append("   `name` = ?,    ");
        sql.append("   `gender` = ?, ");
        sql.append("   `age` = ?,");
        sql.append("   `birthday` = ?,");
        sql.append("   `visit_time` = ?,");
        sql.append("   `dept_id` = ?,");
        sql.append("   `regist_level` = ?,");
        sql.append(" `readme` = ?,");
        sql.append(" `present` =?,");
        sql.append(" `present_treat` = ?,");
        sql.append(" `history` = ?,");
        sql.append("   `allergy` = ?,");
        sql.append("   `disease` = ?,");
        sql.append("   `suit` = ?,");
        sql.append("   `drug` = ?,");
        sql.append("   `userid` = ?,");
        sql.append("   `book` = ?,");
        sql.append("   `fee` = ?,");
        sql.append("   `status` = ?");
        sql.append("   ");
        sql.append(" where `regist_id` =  ?");




        int count = super.update(sql.toString(),
                register.getName(),
                register.getGender(),
                register.getAge(),
                register.getBirthday(),
                register.getVisitTime(),
                register.getDeptId(),
                register.getRegistLevel(),
                register.getReadme(),
                register.getPresent(),
                register.getPresentTreat(),
                register.getHistory(),
                register.getAllergy(),
                register.getDisease(),
                register.getSuit(),
                register.getDrug(),
                register.getUserid(),
                register.getBook(),
                register.getFee(),
                register.getStatus(),

                register.getRegistId()

        );

        return count;

    }

    /**
     * 通用的方法
     *
     * @return
     */

    public int delete(long id) {
        StringBuffer sql = new StringBuffer();

        sql.append(" delete from register where regist_id = ?");

        int count = super.update(sql.toString(),   id        );

        return count;

    }


}
